def backtrack(nums, path, used, res):
    if len(path) == len(nums):
        res.append(''.join(path))
        return
    
    for i in range(len(nums)):
        if used[i] or (i > 0 and nums[i] == nums[i-1] and not used[i-1]):
            continue
        used[i] = True
        path.append(nums[i])
        backtrack(nums, path, used, res)
        path.pop()
        used[i] = False

def unique_permutations(nums):
    nums = sorted(nums)
    res = []
    backtrack(nums, [], [False] * len(nums), res)
    return res

if __name__ == "__main__":
    with open('input.txt', 'r') as file:
        data = file.readlines()
    n = int(data[0])
    elements = data[1].strip()
    
    unique_perms = unique_permutations(elements)
    with open('output.txt', 'w') as file:
        for perm in unique_perms:
            file.write(perm + '\n')
        file.write(str(len(unique_perms)) + '\n')
        
